package com.probox.common.entity.service.wechat.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

import com.probox.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.probox.common.entity.mapper.wechat.WechatMessageListMapper;
import com.probox.common.entity.domain.wechat.WechatMessageList;
import com.probox.common.entity.service.wechat.IWechatMessageListService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 消息发送记录Service业务层处理
 *
 * @author usoft
 * @date 2021-08-16
 */
@Service
@Transactional
public class WechatMessageListServiceImpl extends ServiceImpl<WechatMessageListMapper, WechatMessageList> implements IWechatMessageListService {
    @Autowired
    private WechatMessageListMapper wechatMessageListMapper;


    /**
     * 查询消息发送记录
     *
     * @param messageUid 消息发送记录ID
     * @return 消息发送记录
     */
    @Override
    public WechatMessageList selectWechatMessageListById(Long messageUid) {
        return this.getById(messageUid);
    }

    /**
     * 查询消息发送记录列表
     *
     * @param wechatMessageList 消息发送记录
     * @return 消息发送记录
     */
    @Override
    public List<WechatMessageList> queryList(WechatMessageList wechatMessageList) {
        QueryWrapper<WechatMessageList> queryWrapper = Wrappers.query();
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getMessageUid())) && wechatMessageList.getMessageUid() != null) {
            queryWrapper.eq("MESSAGE_UID", wechatMessageList.getMessageUid());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getPlatformUid())) && wechatMessageList.getPlatformUid() != null) {
            queryWrapper.eq("STORE_UID", wechatMessageList.getPlatformUid());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getBizNo())) && wechatMessageList.getBizNo() != null) {
            queryWrapper.eq("BIZ_NO", wechatMessageList.getBizNo());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getTemplateNo())) && wechatMessageList.getTemplateNo() != null) {
            queryWrapper.eq("TEMPLATE_NO", wechatMessageList.getTemplateNo());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getTemplateTitle())) && wechatMessageList.getTemplateTitle() != null) {
            queryWrapper.eq("TEMPLATE_TITLE", wechatMessageList.getTemplateTitle());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getMemberUid())) && wechatMessageList.getMemberUid() != null) {
            queryWrapper.eq("MEMBER_UID", wechatMessageList.getMemberUid());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getMemberOpenId())) && wechatMessageList.getMemberOpenId() != null) {
            queryWrapper.eq("MEMBER_OPEN_ID", wechatMessageList.getMemberOpenId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getMemberNickName())) && wechatMessageList.getMemberNickName() != null) {
            queryWrapper.eq("MEMBER_NICK_NAME", wechatMessageList.getMemberNickName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getMessageBody())) && wechatMessageList.getMessageBody() != null) {
            queryWrapper.eq("MESSAGE_BODY", wechatMessageList.getMessageBody());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getSendStatus())) && wechatMessageList.getSendStatus() != null) {
            queryWrapper.eq("SEND_STATUS", wechatMessageList.getSendStatus());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getMessageResult())) && wechatMessageList.getMessageResult() != null) {
            queryWrapper.eq("MESSAGE_RESULT", wechatMessageList.getMessageResult());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getSendTime())) && wechatMessageList.getSendTime() != null) {
            queryWrapper.eq("SEND_TIME", wechatMessageList.getSendTime());
        }
        if (StringUtils.isNotEmpty(String.valueOf(wechatMessageList.getSendUser())) && wechatMessageList.getSendUser() != null) {
            queryWrapper.eq("SEND_USER", wechatMessageList.getSendUser());
        }
        queryWrapper.orderByDesc("SEND_TIME");
        return wechatMessageListMapper.selectList(queryWrapper);
    }

    /**
     * 新增消息发送记录
     *
     * @param wechatMessageList 消息发送记录
     * @return 结果
     */
    @Override
    public boolean insertWechatMessageList(WechatMessageList wechatMessageList) {

        return this.save(wechatMessageList);

    }

    /**
     * 修改消息发送记录
     *
     * @param wechatMessageList 消息发送记录
     * @return 结果
     */
    @Override
    public boolean updateWechatMessageList(WechatMessageList wechatMessageList) {

        return this.updateById(wechatMessageList);
    }

    /**
     * 批量删除消息发送记录
     *
     * @param messageUids 需要删除的消息发送记录ID
     * @return 结果
     */
    @Override
    public boolean deleteWechatMessageListByIds(Long[] messageUids) {
        return this.removeByIds(Arrays.asList(messageUids));
    }


}
